#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <array>

std::vector<std::list<int>> gData;   //邻接表
std::array<bool,10> recoedAccessd={false};   //记录已访问过的点
std::queue<int> BFSqueue={};

void initGraphicData()
{
    gData.push_back({1,2,3,4});    //0
    gData.push_back({0,2,4,7,9});  //1
    gData.push_back({0});          //2
    gData.push_back({0,5,6});      //3
    gData.push_back({0,1,3});      //4
    gData.push_back({3,4});        //5
    gData.push_back({3});          //6
    gData.push_back({1,8,10});     //7
    gData.push_back({7,10});       //8
    gData.push_back({1});          //9
    gData.push_back({7});          //10
}

void bfs(int index)
{
    BFSqueue.push(index);
    std::cout<<index<<std::endl;
    recoedAccessd[index]=true;
    while(!BFSqueue.empty())
    {
        int front=BFSqueue.front();
        for(int i : gData[front])
        {
            if(!recoedAccessd[i])
            {
                BFSqueue.push(i);
                std::cout<<i<<std::endl;
                recoedAccessd[i]=true;
            }
        }
        BFSqueue.pop();
    }
}

int main()
{
    initGraphicData();
    bfs(0);
    return 0;
}